import request from '@/utils/request'
import { getToken } from '@/utils/auth'

// 出入库单列表查询
export function pagingStock(query) {
  return request({
    url: 'warehouse/warehouseStock/paging',
    method: 'post',
    params: query
  })
}

// 统计出入库单各状态记录数
export function statStock(warehouseId) {
  return request({
    url: 'warehouse/warehouseStock/statStock',
    method: 'get',
    params: { warehouseId: warehouseId }
  })
}

// 查看详情
export function getStock(stockId) {
  return request({
    url: 'warehouse/warehouseStock/getStock',
    method: 'get',
    params: { stockId: stockId }
  })
}

// 编辑出入库单
export function saveStock(saveStockData) {
  return request({
    url: 'warehouse/warehouseStock/save',
    method: 'post',
    data: saveStockData
  })
}

// 出入库单提交
export function doSubmit(stockId) {
  return request({
    url: 'warehouse/warehouseStock/doSubmit',
    method: 'post',
    data: { stockId: stockId }
  })
}

// 出入库单批量提交
export function batchSubmit(data) {
  return request({
    url: 'warehouse/warehouseStock/batchSubmit',
    method: 'post',
    data: data
  })
}

// 出入库单撤销提交
export function doRevoke(stockId) {
  return request({
    url: 'warehouse/warehouseStock/doRevoke',
    method: 'post',
    data: { stockId: stockId }
  })
}

// 批量撤销提交
export function batchRevoke(data) {
  return request({
    url: 'warehouse/warehouseStock/batchRevoke',
    method: 'post',
    data: data
  })
}

// 审核
export function doAudit(data) {
  return request({
    url: 'warehouse/warehouseStock/doAudit',
    method: 'post',
    data: data
  })
}

// 批量审核
export function batchAudit(data) {
  return request({
    url: 'warehouse/warehouseStock/batchAudit',
    method: 'post',
    data: data
  })
}

// 删除
export function deleteStock(stockId) {
  return request({
    url: 'warehouse/warehouseStock/delete',
    method: 'post',
    data: { stockId: stockId }
  })
}

// 批量删除
export function batchDelete(data) {
  return request({
    url: 'warehouse/warehouseStock/batchDelete',
    method: 'post',
    data: data
  })
}

// 复制
export function copyStock(stockId) {
  return request({
    url: 'warehouse/warehouseStock/doCopyStock',
    method: 'get',
    params: { stockId: stockId }
  })
}

// 获取出入库单商品详情
export function getStockGoods(stockId) {
  return request({
    url: 'warehouse/warehouseStock/get',
    method: 'get',
    params: stockId
  })
}

// 根据条形码查询仓库商品
export function getByBarCode(data) {
  return request({
    url: 'warehouse/warehouseStock/getByBarCode',
    method: 'post',
    data: data
  })
}

// 保存仓库商品
export function saveStockGoods(data) {
  return request({
    url: 'warehouse/warehouseStock/saveStockGoods',
    method: 'post',
    data: data
  })
}

// 出入库单详情 导入商品
export function doImportGoods(data) {
  return request({
    url: 'warehouse/warehouseStock/doImportGoods',
    method: 'post',
    data: data
  })
}

// 批量导入入库
export function batchImportGoods(data) {
  return request({
    url: '/warehouse/warehouseStock/batchImportGoods',
    method: 'post',
    data: data
  })
}

// 当前出入库单 批量删除关联商品
export function batchDeleteStockGoods(data) {
  return request({
    url: '/warehouse/warehouseStock/batchDeleteStockGoods',
    method: 'post',
    data: data
  })
}

// 当前查询条件下所有出库单或已勾选的出库单导出为excel文件
export function doExportByWarehouse(query) {
  let url = process.env.BASE_API + '/warehouse/warehouseStock/doExportByWarehouse'
  let i = 0
  for (var key in query) {
    if (i === 0) {
      url += '?'
    } else {
      url += '&'
    }
    url += key + '=' + query[key]
    i++
  }
  return url + '&accessToken=' + getToken()
}

// 统计出入库单对应的商品数量
export function countStockGoods(stockId) {
  return request({
    url: 'warehouse/warehouseStock/countStockGoods',
    method: 'get',
    params: { stockId: stockId }
  })
}

